"""
内容:将购买商品封装成一个类

"""

"""前置条件,已经登录成功"""
#引入
from ECshop.common.base import create_browser,Base,create_browser_op
import time

#将库存为1的商品,修改购买数量为2
class PageBuy01(Base):
    #属性
    url='http://localhost:8080/ecshop/user.php'
    purchase=("xpath",("//div[@class='textInfo']/form/ul/li[7]/table/tbody/tr/td/a/img"))
    num=('name','number')
    first=('link text','首页')
    camera=("xpath",("//img[@src='images/201605/thumb_img/72_thumb_G_1462956048008.jpg']"))
    zipai=('xpath',("//img[@src='images/201605/thumb_img/63_thumb_G_1462953395609.jpg']"))
    buy=('xpath',("//img[@src='themes/default/images/buybtn1.png']"))
    pay=('xpath',("//img[@src='themes/default/images/checkout.gif']"))
    put_in=('xpath',("//input[@src='themes/default/images/bnt_subOrder.gif']"))
    older_number=('xpath',("//div[@class='flowBox']/h6/font"))
    # older_number=('xpath',("//div[@class='goods-home']/div/div/div/div"))
    older_number_user=('xpath', ("//div[@class='AreaR']/div/div/div/table/tbody/tr[1]/td[1]/a"))
    user=('link text','用户中心')
    user_list=('xpath',("//img[@src='themes/default/images/u3.gif']"))
    backspace=('name','number')
    blank=("xpath",("//form[@id='ECS_FORMBUY']/ul/li[6]/dd[1]/strong"))
    all_price=("xpath","//div[@class='textInfo']/form/ul/li[5]/dd/font")


    #方法
    #打开网页
    def page_buy_web(self):
        self.base_open_web(self.url)

    #点击首页
    def page_buy_first(self):
        self.base_click(self.first)

    #点击智能相机
    def page_buy_camera(self):
        self.base_click(self.camera)
        time.sleep(2)

    #点击自拍杆
    def page_buy_zipai(self):
        self.base_click(self.zipai)

    #立即购买
    def page_buy_buy(self):
        self.base_click(self.buy)

    #立即结算
    def page_buy_pay(self):
        self.base_click(self.pay)

    #提交订单
    def page_buy_put_in(self):
        self.base_click(self.put_in)

    #获取订单成功文本
    def page_buy_older_number(self):
        result=self.base_get_text(self.older_number)
        return result

    #进入用户中心
    def page_buy_user(self):
        self.base_click(self.user)

    #进入我的订单
    def page_buy_user_list(self):
        self.base_click(self.user_list)

    #获取用户中心里面的订单号
    def page_buy_older_number_user(self):
        result_user=self.base_get_text(self.older_number_user)
        return result_user


    #输入框回退
    def page_buy_backspace(self):
        self.base_backspace(self.backspace)

    #修改数量
    def page_buy_number(self,your_content):
        self.base_input_content(self.num,your_content)

    #点击空白处
    def page_buy_bland(self):
        self.base_click(self.blank)

    #获取弹窗内容
    def page_buy_pop(self):
        result=self.base_alert_text()
        return result

    #判断总价变化
    def page_buy_all_price(self):
        result1=self.base_get_text(self.all_price)
        return result1

    #关闭网页
    def page_buy_quit(self):
        self.base_quit()


if __name__ == '__main__':
    #小于库存
    # p1=PageBuy01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    # p1.page_buy_web()
    # p1.page_buy_first()
    # #进入智能相机
    # p1.page_buy_camera()
    # # p1.page_buy_buy()
    # # p1.page_buy_pay()
    # # p1.page_buy_put_in()
    # print(p1.page_buy_older_number())

    #小于库存
    # p1=PageBuy01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    # p1.page_buy_web()
    # p1.page_buy_first()
    # p1.page_buy_zipai()

    #获取最新一个订单号
    # p1=PageBuy01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    # p1.page_buy_web()
    # p1.page_buy_user()
    # p1.page_buy_user_list()
    # print(p1.page_buy_older_number_user())

    #更改数量
    p1=PageBuy01(create_browser_op(r'C:\Users\lenovo\AppData\Local\Google\Chrome\User Data'))
    p1.page_buy_web()
    p1.page_buy_first()
    #进入智能相机
    p1.page_buy_zipai()
    #回退输入框
    p1.page_buy_backspace()
    #输入数量
    p1.page_buy_number(2)
    #点击空白处
    p1.page_buy_bland()
    time.sleep(5)
    # #获取总价
    # print(p1.page_buy_all_price())
    # 立即购买
    p1.page_buy_buy()
    time.sleep(5)
    # 获取文本
    print(p1.page_buy_pop())